//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "ATTraining\main.sqf"
#include <functions\core_macros.h>

TRACE("Start");
TMFPROFILERSTART;

QGVAR(pveh) addPublicVariableEventHandler FUNC(runEvent);
GVAR(ObjectStore) = "Land_HelipadEmpty_F" createVehicleLocal [0,0,0];
GVAR(ObjectStore) allowDamage false;

if (markerType "AT_Training_Ground" != "") then {
	GVAR(AT_POS) = markerPos "AT_Training_Ground";
	GVAR(AT_POS) set [2,0];
	_size = markerSize "AT_Training_Ground";
	_rectangle = (markerShape "AT_Training_Ground" == "RECTANGLE");
	GVAR(AT_SIZE) = (_size select 0) max (_size select 1);
	"AT_Training_Ground" setMarkerAlpha 0;
};

[0,"CreateTarget",FUNC(createTarget)] call FUNC(registerEvent);
[0,"ClearTargets",FUNC(clearTargets)] call FUNC(registerEvent);
[0,"TargetShot",FUNC(targetShot)] call FUNC(registerEvent);
[1,"ResetScores",FUNC(resetScores)] call FUNC(registerEvent);

GVAR(TRAINING_UNITS_TYPES) = ["O_MBT_02_cannon_F","O_MBT_02_arty_F","O_APC_Tracked_02_cannon_F","O_APC_Tracked_02_AA_F","O_APC_Wheeled_02_rcws_F","O_MRAP_02_hmg_F"];
GVAR(TRAINING_DIRECTIONS) = ["North","West","South","East"];

if ((GVAR(AT_POS) distance [0,0,0]) > 0) then {
	if (isServer) then {

	};
	
	if (!isDedicated) then {
		_control_center = missionNamespace getVariable ["AT_ControlCenter",objNull];
		if (!isnull _control_center) then {
			[_control_center,localize "STR_AT_ACTION",{createDialog "AT_ui_Targets";}] call FUNC(addAction);
		};
		GVAR(ZONE_TRIGGER) = createTrigger["EmptyDetector" ,GVAR(AT_POS)];
		GVAR(ZONE_TRIGGER) setTriggerArea [GVAR(AT_SIZE), GVAR(AT_SIZE), 0, false];
		GVAR(ZONE_TRIGGER) setTriggerActivation ["ANY", "PRESENT", true];
		GVAR(ZONE_TRIGGER) setTriggerTimeout [5, 5, 5, true];
		GVAR(ZONE_TRIGGER) setTriggerStatements["player in thisList", "player allowDamage false; player setCaptive true;", "player allowDamage true; player setCaptive false;"];
	};
};

TRACE("End");
TMFPROFILERSTOP;